#include "stm32f10x.h"                  // Device header

void PWM_Init(void)
{ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
	
	GPIO_InitTypeDef GPIO_InitStructure;	
	GPIO_InitStructure.GPIO_Mode =GPIO_Mode_AF_PP  ;
	GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0   ;
	GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz ;
	 GPIO_Init(GPIOA,&GPIO_InitStructure);
	 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE); //6-11gpio初始化
	
	TIM_InternalClockConfig(TIM2);
	
	TIM_TimeBaseInitTypeDef  TIM_TimeBaseInitStructure;
	TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1 ;
	TIM_TimeBaseInitStructure.TIM_CounterMode =TIM_CounterMode_Up ;
	TIM_TimeBaseInitStructure.TIM_Period =99 ; //ARR
	TIM_TimeBaseInitStructure.TIM_Prescaler = 720-1; //PSC
	TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;
	TIM_TimeBaseInit(TIM2,&TIM_TimeBaseInitStructure);
	
	TIM_Cmd(TIM2,ENABLE);
	TIM_OCInitTypeDef TIM_OCInitStructure;
	TIM_OCStructInit(&TIM_OCInitStructure);
	TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;      //没有用到所有的成员，（和高级定时器相关），但建议赋初始值
	TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High ;
	TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable ;
	TIM_OCInitStructure.TIM_Pulse =50 ;    //CCR
  TIM_OC1Init(TIM2,&TIM_OCInitStructure); //pao对应OC1
	
	TIM_Cmd(TIM2,ENABLE);   //打开tim2的时钟
}
void PWM_SetCompare4(uint16_t Compare)
{
      TIM_SetCompare1(TIM2, Compare);//单独 更改通道一的ccr值的
}

 
